<template>
  <div>
    <h2>App组件</h2>
    {{count}}
    <hr>
    <!-- 传入自定义事件 -->
    <!-- <Child @changeCount="changeCount"/> -->
    <Child ref="childComp"/>
  </div>
</template>

<script>
import Child from "@/components/Child";
export default {
  name: "App",
  components: {
    Child,
  },
  data() {
    return {
      count:0
    }
  },
  // 初始化的时候，对某一个子组件绑定自定义事件
  // $once 只触发一次
  mounted() {
    this.$refs.childComp.$once("changeCount",this.changeCount)
  },
  methods: {
    changeCount(value){
      this.count+= value
    }
  },
};
</script>

<style>
</style>